--[[
描述 ： 蓝牙 类 
作者 ： 付大志
修改 ： jwg- qt
时间 ： 14/12/01
]]

 

MLBluetooth = Class(MLPlugin,'MLBluetooth'); 
MLBluetooth.mInstance=nil;

MLBluetooth.mRecvType=nil;

MLBluetooth.STATE_NONE = 0;
MLBluetooth.STATE_LISTEN =1;       
MLBluetooth.STATE_CONNECTING = 2; 
MLBluetooth.STATE_CONNECTED = 3;  


MLBluetooth.REVC_TYPE_STRING = 0;
MLBluetooth.REVC_TYPE_BYTE = 1;
--[[
功能：   初始化 蓝牙 实例
参数：	无	
返回：   定时器 实例
]] 
function  MLBluetooth:initBluetooth()


	--self.mInstance  =self:getPlugInst('com.MLink.plugins.MLBluetooth.MYBluetooth',MLNative.MLContext); 
	--self.mRecvType = MLBluetooth.REVC_TYPE_STRING ;
	return self;
end 


function  MLBluetooth:connect()
	--return self.mInstance:blueConnect();
end 

function  MLBluetooth:disConnect()
	--return self.mInstance:bluedDisConnect();
end 

function  MLBluetooth:sendMsg(text)
	--return self.mInstance:blueSendMessage(text);
end 

function  MLBluetooth:sendData(data)
    if not data then return end 
	--return self.mInstance:blueSendData(data.mInstance);
end 


function  MLBluetooth:setRevcType(type)
	 self.mRecvType  = type;
	--return self.mInstance:bluedSetRevcType(type);
end 


 
function MLBluetooth:onCallBack(resultCode,arg) 
	print('MLEditView:onCallBack',resultCode,arg);
    if resultCode ==  0 then
    	if self~=nil then
			if self.onBluetoothState ~=nil then
				self.onBluetoothState(state);
			end
		end 
	elseif resultCode ==1 then
		if self~=nil then 
			if self.onBluetoothName ~=nil then 
				self.onBluetoothName(arg);
			end
		end 
    elseif resultCode ==2 then
    	if self.onBluetoothRecv then
				 if self.mRecvType  == MLBluetooth.REVC_TYPE_STRING then
				    self.onBluetoothRecv(msg);
				 else 
				 	 local data = MLData.new():initDataWithInst(arg);
				 	 self.onBluetoothRecv(data);
				 end 
			end 
    end
end
 